/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.geaSV.busquedas;

import com.geaSV.conexiones.conectarBD;
import com.geaSV.entities.MaterialE;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author vash
 */
public class busquedaMateriales {
 private Connection conx=null;
 private Statement sttm; 
 private ResultSet rs;   
 
  public List<MaterialE> obtenerMateriales() throws SQLException{
        List <MaterialE> lst=new ArrayList<MaterialE> (0);
        try{
            conx= conectarBD.conectar();
            sttm= conx.createStatement();
            rs=sttm.executeQuery("SELECT m.*,p.nombre as nomp  FROM material m,proveedor p, material_proveedor mp "
                    + "where m.id=mp.id_mat and p.id=mp.id_prov ");
            while(rs.next()){
            MaterialE S=new MaterialE();
            S.setId(rs.getInt("id"));
            S.setNombre(rs.getString("nombre"));
            S.setuMedida(rs.getString("unidadMedida"));
            S.setDescripcion(rs.getString("descripcion"));
            S.setCosto(rs.getDouble("costo"));
            S.setNomProv(rs.getString("nomp"));
           
          
            lst.add(S);
            }
        }catch(Exception e){
            System.out.println(e.getMessage());
            
        }finally{
            rs.close();
            sttm.close();
            conx.close();
            return lst;
        }
}

public MaterialE obtenerMaterial(int id) throws SQLException{
      MaterialE S=new MaterialE();
        try{
            conx= conectarBD.conectar();
            sttm= conx.createStatement();
            rs=sttm.executeQuery("SELECT * FROM material m where m.id="+id+"");
            while(rs.next()){
            
            S.setId(rs.getInt("id"));
            S.setNombre(rs.getString("nombre"));
            S.setuMedida(rs.getString("unidadMedida"));
            S.setDescripcion(rs.getString("descripcion"));
            S.setCosto(rs.getDouble("costo"));
            S.setCantidad(rs.getDouble("cantidad"));
                 
            
            }
        }catch(Exception e){
            System.out.println(e.getMessage());
            
        }finally{
            rs.close();
            sttm.close();
            conx.close();
            return S;
        }
}





}
